function d = discrate(sd, md, rv, price, basis)
%DISCRATE Discount rate of security.
%   Finds the discount rate of a security given the settlement date (SD), the
%   maturity date (MD), par value (RV), and PRICE.
%
%   DRATE = discrate(SD, MD, RV, PRICE)
%   DRATE = discrate(SD, MD, RV, PRICE, BASIS)
%
%   Optional Inputs: BASIS
%
%   Inputs:
%   Enter dates as serial date numbers or date strings.
%
%   SD      -  Settlement date
%   MD      -  Maturity date
%   RV      -  Par value
%   PRICE   -  Price
%
%   Optional Inputs:
%   BASIS   -  Day-count basis:
%              0 = actual/actual (default)
%              1 = 30/360 SIA
%              2 = actual/360
%              3 = actual/365
%              4 = 30/360 PSA
%              5 = 30/360 ISDA
%              6 = 30E/360
%              7 = actual/365 Japanese
%              8 = actual/actual ISMA
%              9 = actual/360 ISMA
%             10 = actual/365 ISMA
%             11 = 30/360 ISMA
%             12 = actual/365 ISDA
%             13 = bus/252
%
%   Outputs:
%   DRATE - Discount rate in decimal.
%
%   For example:
%      DRATE = discrate('12-jan-1994', '25-jun-1994', 100, 97.74, 0)
%
%      DRATE = 0.0503 % or a discount rate of 5.03%.
%
%   See also ACRUDISC, FVDISC, PRDISC, YLDDISC.
%
%   Reference: Mayle, Standard Securities Calculation Methods, Volumes
%              I-II, 3rd edition.  Formula 1*.

%   Copyright 1995-2006 The MathWorks, Inc.
%   $Revision: 1.6.2.9 $   $Date: 2009/05/07 18:23:25 $

if nargin < 5
    basis = 0;
end
if nargin < 4
    error('finance:discrate:notEnoughInputs', ...
        'Too few inputs.');
end

[~, sd, md, ~, basis, ~, ~, ...
    ~, ~, ~, rv] = ...
    instargbond([],sd,md,[],basis,[],[],[],[],[],rv);

[sd, md, rv, price, basis] = ...
    finargsz(1,sd, md, rv, price, basis);

% Formula 1*, page 45
d = reshape((1-price(:)./rv(:)) .* (1./yearfrac(sd,md,basis)), size(rv));